var linkClick = true;
var textRoomCheckInPending ="";
var textRoomCheckInPendingPrint ="";
var textRoomTemp="";
var textRoomTempPrint="";
var textRoomCheckOutPending = "";
var textRoomCheckOutPendingPrint = "";
var textRoomBookingDeposits = "";
var textRoomBookingDepositsPrint = "";
var textRoomCancelResv="";
var textRoomCancelResvPrint="";
var textPaymentTracker = "";
var textExpressCheckOut = "";
var textExpressCheckOutPrint = "";
var textNoShow = "";
var textNoShowPrint = "";
var textRoomGroup = "";
var getStatusResInGroup = "";
setTimeout(function(){showNumberall_reservation();},50);
function showNumberall_reservation(){
	var link = "/reservationService?func=getReservationAllPoint";
	simpleserviceSyn(link,null,showNumberall_reservationSuccess);
}
function clearCountRoommanagement(){
	var point = 0;
	$("#All").html(point);
	$("#CheckoutOnly").html(point);
	$("#ExpressAll").html(point);
	$("#CheckInPending").html(point);
	$("#Temp").html(point);
	$("#CheckOutPending").html(point);
	$("#Deposits").html(point);
	$("#GuestName").html(point);
	$("#CancelResv").html(point);
	$("#NoShow").html(point);
	$("#PaymentTracker").html(point);
}
function showNumberall_reservationSuccess(data){
	clearCountRoommanagement();
	if(jQuery.trim(data)!=""&&jQuery.trim(data)!="[]"){
		var objArray = new Array();
		objArray = JSON.parse(data);
		var checkTypePage = "";
		if(objArray.AllCount!=null){
			$("#All").html(objArray.AllCount);
		}
		if(objArray.CheckoutOnlyCount!=null){
			$("#CheckoutOnly").html(objArray.CheckoutOnlyCount);
		}
		if(objArray.ExpressAllCount!=null){
			$("#ExpressAll").html(objArray.ExpressAllCount);
		}
		if(objArray.CheckInPendingCount!=null){
			$("#CheckInPending").html(objArray.CheckInPendingCount);
		}
		if(objArray.TempCount!=null){
			$("#Temp").html(objArray.TempCount);
		}
		if(objArray.CheckOutPendingCount!=null){
			$("#CheckOutPending").html(objArray.CheckOutPendingCount);
		}
		if(objArray.DepositsCount!=null){
			$("#Deposits").html(objArray.DepositsCount);
		}
		if(objArray.GuestNameCount!=null){
			$("#GuestName").html(objArray.GuestNameCount);
		}
		if(objArray.CancelResvCount!=null){
			$("#CancelResv").html(objArray.CancelResvCount);
		}
		if(objArray.NoShowCount!=null){
			$("#NoShow").html(objArray.NoShowCount);
		}
		if(objArray.PaymentTrackerCount!=null){
			$("#PaymentTracker").html(objArray.PaymentTrackerCount);
		}
	}
}

function clearData(){
	 textRoomGroup = "";
	 getStatusResInGroup = "";
	 checkStatusResInGroup = "";
	 checkStatusCheckoutResInGroup = "";
	 checkStatusResvResInGroup = "";
	 checkStatusCheckInResInGroup = "";
	 showStatusResInGroup = "";
	 checkStatsResCheckIn = "";
}
function getResInGroup(dataResInGroup){
	var objArray = new Array();
	objArray = JSON.parse(dataResInGroup);
	getStatusResInGroup = objArray.reservationStatusName;
}
function checkedFilter(output,valueSearch,nameReservation,firstSelect,Objtitle,ObjgroupId,typeReservation,ObjId){
	if(output=="textSearch"){
		if(valueSearch!=""){
			var checkG = "";
			checkG = valueSearch.substring(0,1);
			if(checkG=="G"||checkG=="g")
				valueSearch = valueSearch.substring(1,valueSearch.length);
			if(!(valueSearch==ObjgroupId||valueSearch==ObjId||valueSearch==nameReservation[0])){return 1;}
			if(typeReservation=="G"){
				if(ObjgroupId=="0"){return 1;}
				if(firstSelect=="Checked-in Rooms"){
						if(Objtitle!="Checked-in Rooms"){return 1;}
				}
				if(firstSelect=="Checked-out Rooms"){
						if(Objtitle!="Checked-out Rooms"){return 1;}
				}
				if(firstSelect=="Reserved Rooms"){
					if(Objtitle!="Reserved Rooms"){return 1;}
				}
			}else if(typeReservation=="S"){
				if(ObjgroupId!="0"){return 1;}
				if(firstSelect=="Checked-in Rooms"){
					if(Objtitle!="Checked-in Rooms"){return 1;}
				}
				if(firstSelect=="Checked-out Rooms"){
						if(Objtitle!="Checked-out Rooms"){return 1;}
				}
				if(firstSelect=="Reserved Rooms"){
					if(Objtitle!="Reserved Rooms"){return 1;}
				}
			}else if(typeReservation=="A"){
				if(firstSelect=="Checked-in Rooms"){
					if(Objtitle!="Checked-in Rooms"){return 1;}
				}
				if(firstSelect=="Checked-out Rooms"){
						if(Objtitle!="Checked-out Rooms"){return 1;}
				}
				if(firstSelect=="Reserved Rooms"){
					if(Objtitle!="Reserved Rooms"){return 1;}
				}
			}else if(firstSelect=="Checked-in Rooms"){
				if(Objtitle!="Checked-in Rooms"){return 1;}
				if(typeReservation=="G"){
					if(ObjgroupId=="0"){return 1;}
				}else if(typeReservation=="S"){
					if(ObjgroupId!="0"){return 1;}
				}
			}else if(firstSelect=="Checked-out Rooms"){
				if(Objtitle!="Checked-out Rooms"){return 1;}
				if(typeReservation=="G"){
					if(ObjgroupId=="0"){return 1;}
				}else if(typeReservation=="S"){
					if(ObjgroupId!="0"){return 1;}
				}
			}else if(firstSelect=="Reserved Rooms"){
				if(Objtitle!="Reserved Rooms"){return 1;}
				if(typeReservation=="G"){
					if(ObjgroupId=="0"){return 1;}
				}else if(typeReservation=="S"){
					if(ObjgroupId!="0"){return 1;}
				}
			}else if(firstSelect=="reservationType_A"){
				if(typeReservation=="G"){
					if(ObjgroupId=="0"){return 1;}
				}else if(typeReservation=="S"){
					if(ObjgroupId!="0"){return 1;}
				}
			}
		}else{
			if(typeReservation=="G"){
				if(ObjgroupId=="0"){return 1;}
				if(firstSelect=="Checked-in Rooms"){
						if(Objtitle!="Checked-in Rooms"){return 1;}
				}
				if(firstSelect=="Checked-out Rooms"){
						if(Objtitle!="Checked-out Rooms"){return 1;}
				}
				if(firstSelect=="Reserved Rooms"){
					if(Objtitle!="Reserved Rooms"){return 1;}
				}
			}else if(typeReservation=="S"){
				if(ObjgroupId!="0"){return 1;}
				if(firstSelect=="Checked-in Rooms"){
					if(Objtitle!="Checked-in Rooms"){return 1;}
				}
				if(firstSelect=="Checked-out Rooms"){
						if(Objtitle!="Checked-out Rooms"){return 1;}
				}
				if(firstSelect=="Reserved Rooms"){
					if(Objtitle!="Reserved Rooms"){return 1;}
				}
			}else if(typeReservation=="A"){
				if(firstSelect=="Checked-in Rooms"){
					if(Objtitle!="Checked-in Rooms"){return 1;}
				}
				if(firstSelect=="Checked-out Rooms"){
						if(Objtitle!="Checked-out Rooms"){return 1;}
				}
				if(firstSelect=="Reserved Rooms"){
					if(Objtitle!="Reserved Rooms"){return 1;}
				}
			}else if(firstSelect=="Checked-in Rooms"){
				if(Objtitle!="Checked-in Rooms"){return 1;}
				if(typeReservation=="G"){
					if(ObjgroupId=="0"){return 1;}
				}else if(typeReservation=="S"){
					if(ObjgroupId!="0"){return 1;}
				}
			}else  if(firstSelect=="Checked-out Rooms"){
				if(Objtitle!="Checked-out Rooms"){return 1;}
				if(typeReservation=="G"){
					if(ObjgroupId=="0"){return 1;}
				}else if(typeReservation=="S"){
					if(ObjgroupId!="0"){return 1;}
				}
			}else if(firstSelect=="Reserved Rooms"){
				if(Objtitle!="Reserved Rooms"){return 1;}
				if(typeReservation=="G"){
					if(ObjgroupId=="0"){return 1;}
				}else if(typeReservation=="S"){
					if(ObjgroupId!="0"){return 1;}
				}
			}else if(firstSelect=="reservationType_A"){
				if(typeReservation=="G"){
					if(ObjgroupId=="0"){return 1;}
				}else if(typeReservation=="S"){
					if(ObjgroupId!="0"){return 1;}
				}
			}
		}
	}else if(output=="G"){
		if(ObjgroupId=="0"){return 1;}
		if(firstSelect=="Checked-in Rooms"){
				if(Objtitle!="Checked-in Rooms"){return 1;}
		}
		if(firstSelect=="Checked-out Rooms"){
				if(Objtitle!="Checked-out Rooms"){return 1;}
		}
		if(firstSelect=="Reserved Rooms"){
			if(Objtitle!="Reserved Rooms"){return 1;}
		}
	}else if(output=="S"){
		if(ObjgroupId!="0"){return 1;}
		if(firstSelect=="Checked-in Rooms"){
			if(Objtitle!="Checked-in Rooms"){return 1;}
		}
		if(firstSelect=="Checked-out Rooms"){
				if(Objtitle!="Checked-out Rooms"){return 1;}
		}
		if(firstSelect=="Reserved Rooms"){
			if(Objtitle!="Reserved Rooms"){return 1;}
		}
	}else if(output=="A"){
		if(firstSelect=="Checked-in Rooms"){
			if(Objtitle!="Checked-in Rooms"){return 1;}
		}
		if(firstSelect=="Checked-out Rooms"){
				if(Objtitle!="Checked-out Rooms"){return 1;}
		}
		if(firstSelect=="Reserved Rooms"){
			if(Objtitle!="Reserved Rooms"){return 1;}
		}
	}else if(output=="Checked-in Rooms"){
		if(Objtitle!="Checked-in Rooms"){return 1;}
		if(typeReservation=="G"){
			if(ObjgroupId=="0"){return 1;}
		}else if(typeReservation=="S"){
			if(ObjgroupId!="0"){return 1;}
		}
	}else  if(output=="Checked-out Rooms"){
		if(Objtitle!="Checked-out Rooms"){return 1;}
		if(typeReservation=="G"){
			if(ObjgroupId=="0"){return 1;}
		}else if(typeReservation=="S"){
			if(ObjgroupId!="0"){return 1;}
		}
	}else if(firstSelect=="Reserved Rooms"){
		if(Objtitle!="Reserved Rooms"){return 1;}
		if(typeReservation=="G"){
			if(ObjgroupId=="0"){return 1;}
		}else if(typeReservation=="S"){
			if(ObjgroupId!="0"){return 1;}
		}
	}else if(output=="reservationType_A"){
		if(typeReservation=="G"){
			if(ObjgroupId=="0"){return 1;}
		}else if(typeReservation=="S"){
			if(ObjgroupId!="0"){return 1;}
		}
	}
}
//export excel
function exportCsv(){
    var	codeReservation = $("#SearchAll_guestPage").val();
    var checkinValue    = $("#calendar_btw_checkin").attr("dateofbtwcheckin");
    var checkoutValue   = $("#calendar_btw_checkout").attr("dateofbtwcheckout");
    var typeValue       = $("#typeCheckReservationGuest option:selected").html().trim()+","+$("#typeCheckReservationGuest option:selected").val().trim();
    var statusValue     = $("#TypeResvGuest option:selected").html().trim()+","+$("#TypeResvGuest option:selected").val().trim();
	var typeExport 		= $("#optionExport").val();
    var link = "/reservationService?func=exportFile&title="+titleGuest+"&code="+codeReservation+"&dateCheckin="+checkinValue+"&dateCheckout="+checkoutValue+"&typeReservation="+typeValue+
	"&status="+statusValue+"&typeExport="+typeExport;
	window.location=parent.window.location.origin+link;
}
//print 
function printDiv(divID,id) {
  var checkId = $(id).attr('id');
	var mainHeader = "<table width='100%'>" +
			"<tr valign='top'>" +
			"<td width='15%'>" +
			"<img src='images/ihotel.jpeg' style='width:100px; height:100px;'>" +
			"</td>" +
			"<td align='right'>" +
			"<table style='font-size:10px;'>" +
			"<tr>" +
			"<td style='margin-bottom:5px; border-bottom:#999 dotted 1px;'>" +
			"<span style='font-weight: bold;' >I Hotel </span>" +
			"</td>" +
			"</tr>" +
			"<tr><td>Thakor - 4800</td></tr>" +
			"<tr><td>Nakhonpanom, Thailand</td></tr>" +
			"<tr><td><span style='font-weight: bold;'>Phone:</span>   +6642543355</td></tr>" +
			"<tr><td><span style='font-weight: bold;'>Fax:</span>     +6642543377</td></tr>" +
			"<tr><td><span style='font-weight: bold;'>Email:</span>   ihotelthailands@gmail.com</td></tr>" +
			"<tr><td><span style='font-weight: bold;'>Website</span>  :www.ihotel.co.th</td></tr>" +
			"</table>"+
			"</td>"+
			"</tr>" +
			"</table>";
  var title = $("#tappage_roommanage_menu_"+checkId).attr("useprint");
  var text ='';
  if(checkId=="CheckOutExpressListRoomManageMent"){
  	text  = '<html><head>'+
		'<title></title></head><body>'+
		mainHeader+
		'<table width="100%" border="0" style="text-align:center; font-size:10px;">'+
		'<tr><td colspan=10 style="text-align:center;"><span style="font-weight: bold;">'+title+'</span></td></tr>'+
		'<tr>'+
			'<td> '+
				'#'+
			'</td>'+
			'<td>' +
				'<span style="font-weight: bold;">'+groupCode+'/'+resId+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+typeSource+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+groupGuestName+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+duration+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+typeRoom+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+folioNumber+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+TotalSum+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+expressPaidPrint+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+expressBalance+'</span>'+
			'</td>'+
		'</tr>'+
		textPrint+
	'</table></body>';
  }else if(checkId=="BookingDepositsListRoomManageMent"){
  	text  = '<html><head>'+
		'<title></title></head><body>'+
		mainHeader+
		'<table width="100%" border="0" style="text-align:center; font-size:10px;">'+
		'<tr><td colspan=10 style="text-align:center;"><span style="font-weight: bold;">'+title+'</span></td></tr>'+
		'<tr>'+
			'<td> '+
				'#'+
			'</td>'+
			'<td>' +
				'<span style="font-weight: bold;">'+groupCode+'/'+resId+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+typeResv+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+groupGuestName+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+duration+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+expressPaid+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+expressDeposits+'</span>'+
			'</td>'+
		'</tr>'+
		textPrint+
	'</table></body>';
  }else if(checkId=="PaymentTrackerListRoomManageMent"){
  	text  = '<html><head>'+
		'<title></title></head><body>'+
		mainHeader+
		'<table width="100%" border="0" style="text-align:center; font-size:10px;">'+
		'<tr><td colspan=10 style="text-align:center;"><span style="font-weight: bold;">'+title+'</span></td></tr>'+
		'<tr>'+
			'<td> '+
				'#'+
			'</td>'+
			'<td>' +
				'<span style="font-weight: bold;">'+groupCode+'/'+resId+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+groupGuestName+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+duration+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+TrackHoardingPaid+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+dueTillNow+'</span>'+
			'</td>'+
		'</tr>'+
		textPrint+
	'</table></body>';
  }else if(checkId=="GuestNameListRoomManageMent"){
  	text  = '<html><head>'+
		'<title></title></head><body>'+
		mainHeader+
		'<table width="100%" border="0" style="text-align:center; font-size:10px;">'+
		'<tr><td colspan=10 style="text-align:center;"><span style="font-weight: bold;">'+title+'</span></td></tr>'+
		'<tr>'+
			'<td> '+
				'#'+
			'</td>'+
			'<td>' +
				'<span style="font-weight: bold;">'+groupCode+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+resId+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+groupGuestName+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+GuestListcheckin+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+GuestListcheckout+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+GuestListStatus+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+duration+'</span>'+
			'</td>'+
			'<td>'+
			'<span style="font-weight: bold;">'+GuestListtypeRoom+'</span>'+
		'</td>'+
		'</tr>'+
		textPrint+
	'</table></body>';
  }else if(checkId=="CancelReservationListRoomManageMent"){
	  text  = '<html><head>'+
		'<title></title></head><body>'+
		mainHeader+
		'<table width="100%" border="0" style="text-align:center; font-size:10px;">'+
		'<tr><td colspan=10 style="text-align:center;"><span style="font-weight: bold;">'+title+'</span></td></tr>'+
		'<tr>'+
			'<td> '+
				'#'+
			'</td>'+
			'<td>' +
				'<span style="font-weight: bold;">'+groupCode+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+resId+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+groupGuestName+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+duration+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+typeRoom+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+pax+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+statusPrint+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+amountPrint+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+chargeAmount+'</span>'+
			'</td>'+
			'<td>'+
			'<span style="font-weight: bold;">'+reasonPrint+'</span>'+
			'</td>'+
		'</tr>'+
		textPrint+
	'</table></body>';
  }else if(checkId=="CheckInListRoomManageMent"){
	  text  = '<html><head>'+
		'<title></title></head><body>'+
		mainHeader+
		'<table width="100%" border="0" style="text-align:center; font-size:10px;">'+
		'<tr><td colspan=10 style="text-align:center;"><span style="font-weight: bold;">'+title+'</span></td></tr>'+
		'<tr>'+
			'<td> '+
				'#'+
			'</td>'+
			'<td>' +
				'<span style="font-weight: bold;">'+groupCode+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+resId+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+groupGuestName+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+duration+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+typeRoom+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+pax+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+statusPrint+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+amountPrint+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+notePrint+'</span>'+
			'</td>'+
			'<td>'+
			'<span style="font-weight: bold;">'+displayStatus+'</span>'+
			'</td>'+
		'</tr>'+
		textPrint+
	'</table></body>';
  }else if(checkId=="TempListRoomManageMent"){
	  text  = '<html><head>'+
		'<title></title></head><body>'+
		mainHeader+
		'<table width="100%" border="0" style="text-align:center; font-size:10px;">'+
		'<tr><td colspan=10 style="text-align:center;"><span style="font-weight: bold;">'+title+'</span></td></tr>'+
		'<tr>'+
			'<td> '+
				'#'+
			'</td>'+
			'<td>' +
				'<span style="font-weight: bold;">'+groupCode+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+resId+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+groupGuestName+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">หมายเลขโทรศัพท์</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">อีเมล์</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+duration+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+typeRoom+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+pax+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+statusPrint+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+amountPrint+'</span>'+
			'</td>'+
			'<td>'+
			'<span style="font-weight: bold;">'+notePrint+'</span>'+
		'</td>'+
		'</tr>'+
		textPrint+
	'</table></body>';
  }else if(checkId=="NoShowListRoomManageMent"){
	  text  = '<html><head>'+
		'<title></title></head><body>'+
		mainHeader+
		'<table width="100%" border="0" style="text-align:center; font-size:10px;">'+
		'<tr><td colspan=10 style="text-align:center;"><span style="font-weight: bold;">'+title+'</span></td></tr>'+
		'<tr>'+
			'<td> '+
				'#'+
			'</td>'+
			'<td>' +
				'<span style="font-weight: bold;">'+groupCode+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+resId+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+groupGuestName+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+duration+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+typeRoom+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+pax+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+statusPrint+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+amountPrint+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+chargeAmount+'</span>'+
			'</td>'+
			'<td>'+
				'<span style="font-weight: bold;">'+notePrint+'</span>'+
			'</td>'+
		'</tr>'+
		textPrint+
	'</table></body>';
  }else{
  	text  = '<html><head>'+
			'<title></title></head><body>'+
			mainHeader+
			'<table width="100%" border="0" style="text-align:center; font-size:10px;">'+
			'<tr><td colspan=10 style="text-align:center;"><span style="font-weight: bold;">'+title+'</span></td></tr>'+
			'<tr>'+
				'<td> '+
					'#'+
				'</td>'+
				'<td>' +
					'<span style="font-weight: bold;">'+groupCode+'</span>'+
				'</td>'+
				'<td>'+
					'<span style="font-weight: bold;">'+resId+'</span>'+
				'</td>'+
				'<td>'+
					'<span style="font-weight: bold;">'+groupGuestName+'</span>'+
				'</td>'+
				'<td>'+
					'<span style="font-weight: bold;">'+duration+'</span>'+
				'</td>'+
				'<td>'+
					'<span style="font-weight: bold;">'+typeRoom+'</span>'+
				'</td>'+
				'<td>'+
					'<span style="font-weight: bold;">'+pax+'</span>'+
				'</td>'+
				'<td>'+
					'<span style="font-weight: bold;">'+statusPrint+'</span>'+
				'</td>'+
				'<td>'+
					'<span style="font-weight: bold;">'+amountPrint+'</span>'+
				'</td>'+
				'<td>'+
					'<span style="font-weight: bold;">'+notePrint+'</span>'+
				'</td>'+
			'</tr>'+
			textPrint+
		'</table></body>';
  }
  myWindow=window.open();
  myWindow.document.write(text);
  myWindow.print();
  myWindow.focus();
  //Print Page
}

function cancelTempGroup(tempId,groupTempId){
	confirmDialog(confirmCancelTempReservationToGroup,function() {
		var link = "/reservationService?func=removeResTemp&resId=" +tempId+"&type=Group&groupId="+groupTempId;
		simpleserviceSyn(link,null,cancelTemResGroupSuccess,tempId);
	});
}

function cancelTemResGroupSuccess(data,tempId){
	for(var i =0; i<oldObjArrayTemp.length;i++){
		if(oldObjArrayTemp[i].subList!=""&&oldObjArrayTemp[i].subList!=null){
			var arrayListSubRes = oldObjArrayTemp[i].subList;
			for(var j = 0;j<arrayListSubRes.length;j++){
				if(arrayListSubRes[j].id==tempId){
					delete oldObjArrayTemp[i].subList[j];
					oldObjArrayTemp[i].subList = oldObjArrayTemp[i].subList.filter(function(a){return typeof a !== 'null';});
				}
			}
			if(oldObjArrayTemp[i].subList==""){
				delete oldObjArrayTemp[i];
				oldObjArrayTemp = oldObjArrayTemp.filter(function(a){return typeof a !== 'null';});
			}
		}
	}
	DisplayframeMainMenu("Front Desk");
	cerltimespan(savedSpan);
}

function cancelTemp(tempId){
	confirmDialog(confirmCancelTempReservationToGroup,function() {
		var link = "/reservationService?func=removeResTemp&resId=" +tempId+"&type=Single&groupId=0";
		simpleserviceSyn(link,null,cancelTemResSuccess,tempId);
	});
}

function cancelTemResSuccess(data,tempId){
	objArray = JSON.parse(data);
	var checkLogOut = CheckSession(objArray);
	if(checkLogOut)
		return;
	for(var i =0;i<oldObjArrayTemp.length;i++){
		if(oldObjArrayTemp[i].id==tempId){
			delete oldObjArrayTemp[i];
			oldObjArrayTemp = oldObjArrayTemp.filter(function(a){return typeof a !== 'null';});
			indexPush = 0;
		}
	}
	DisplayframeMainMenu("Front Desk");
	cerltimespan(savedSpan);
}

function editAfterResTemp(e) {
	confirmDialog(confirmReservation,function() {
		var sellRoom_editAfRes = false;
		var roomStatus_editAfRes = 'Reserved Rooms';
		var nowDate = new Date();
		mkMonth=nowDate.getMonth()+1;
		mkMonth=new String(mkMonth);
		if(mkMonth.length==1){
			mkMonth="0"+mkMonth;
		}
		mkDay=nowDate.getDate();
		mkDay=new String(mkDay);
		if(mkDay.length==1){
			mkDay="0"+mkDay;
		}
		var Hours = nowDate.getHours();
		var Minutes = nowDate.getMinutes();
		nowDate = nowDate.getFullYear() +"-"+ mkMonth +"-"+ mkDay +" "+Hours+":"+Minutes;
		var link = "/reservationService?func=changeTempToReservatonRoomManage&resId=" +e+"&reservationstatus="+roomStatus_editAfRes+"&sellroom="+sellRoom_editAfRes+"&isassign=false&dateCheckin="+nowDate;
		simpleserviceSyn(link,null,chageTemResSuccess,e);
	});
}
function chageTemResSuccess(data,tempId){
	var indexPush = 0;
	var indexPushGroup = 0;
	var countIndex = 0;
	objArray = JSON.parse(data);
	var checkLogOut = CheckSession(objArray);
	if(checkLogOut)
		return;
	setTimeout(function(){showNumberall_reservation();},50);
	for(var i =0; i<oldObjArrayTemp[0].length;i++){
		if(oldObjArrayTemp[0][i].subList!=""&&oldObjArrayTemp[0][i].subList!=null){
			var arrayListSubRes = oldObjArrayTemp[0][i].subList;
			for(var j = 0;j<arrayListSubRes.length;j++){
				if(arrayListSubRes[j].id==tempId){
					if(indexPushGroup==0){
						indexPushGroup = j;
					}
					delete oldObjArrayTemp[0][i].subList[j];
					oldObjArrayTemp[0][i].subList = oldObjArrayTemp[0][i].subList.filter(function(a){return typeof a !== 'null';});
					oldObjArrayTemp[0][i].subList.splice(indexPushGroup,0,objArray);
					indexPush = 0;
					CreateMenu(getCurrentTabData().title,"TempListRoomManageMent");
				//	DisplayframeMainMenu("Front Desk");
					cerltimespan(savedSpan);
				}
			}
		}else{
			if(oldObjArrayTemp[0][i].id==objArray.id){
				if(indexPush == 0){
					indexPush = i;
				}
				delete oldObjArrayTemp[0][i];
				oldObjArrayTemp[0] = oldObjArrayTemp[0].filter(function(a){return typeof a !== 'null';});
				oldObjArrayTemp[0].splice(indexPush,0,objArray);
				indexPush = 0;
				CreateMenu(getCurrentTabData().title,"TempListRoomManageMent");
			//	DisplayframeMainMenu("Front Desk");
				cerltimespan(savedSpan);
			}
		}
	}
}

function editAfterResCancellation(e) {
	confirmDialog(confirmReservation,function() {
		var sellRoom_editAfRes = false;
		var roomStatus_editAfRes = 'Reserved Rooms';
		var nowDate = new Date();
		mkMonth=nowDate.getMonth()+1;
		mkMonth=new String(mkMonth);
		if(mkMonth.length==1){
			mkMonth="0"+mkMonth;
		}
		mkDay=nowDate.getDate();
		mkDay=new String(mkDay);
		if(mkDay.length==1){
			mkDay="0"+mkDay;
		}
		var Hours = nowDate.getHours();
		var Minutes = nowDate.getMinutes();
		nowDate = nowDate.getFullYear() +"-"+ mkMonth +"-"+ mkDay +" "+Hours+":"+Minutes;
		var link = "/reservationService?func=changeTempToReservatonRoomManage&resId=" +e+"&reservationstatus="+roomStatus_editAfRes+"&sellroom="+sellRoom_editAfRes+"&isassign=false&dateCheckin="+nowDate;
		simpleserviceSyn(link,null,chageCancelResSuccess,e);
	});
}
function chageCancelResSuccess(data,cancelId){
	
	var indexPush = 0;
	var indexPushGroup = 0;
	var countIndex = 0;
	objArray = JSON.parse(data);
	for(var i =0; i<oldObjArrayCancel.length;i++){
		if(oldObjArrayCancel[i].subList!=""&&oldObjArrayCancel[i].subList!=null){
			var arrayListSubRes = oldObjArrayCancel[i].subList;
			for(var j = 0;j<arrayListSubRes.length;j++){
				if(arrayListSubRes[j].id==cancelId){
					if(indexPushGroup==0){
						indexPushGroup = j;
					}
					delete oldObjArrayCancel[i].subList[j];
					oldObjArrayCancel[i].subList = oldObjArrayCancel[i].subList.filter(function(a){return typeof a !== 'null';});
					oldObjArrayCancel[i].subList.splice(indexPushGroup,0,objArray);
					indexPush = 0;
					DisplayframeMainMenu("Front Desk");
					cerltimespan(savedSpan);
				}
			}
		}else{
			if(oldObjArrayCancel[i].id==objArray.id){
				if(indexPush == 0){
					indexPush = i;
				}
				delete oldObjArrayCancel[i];
				oldObjArrayCancel = oldObjArrayCancel.filter(function(a){return typeof a !== 'null';});
				oldObjArrayCancel.splice(indexPush,0,objArray);
				indexPush = 0;
				DisplayframeMainMenu("Front Desk");
				cerltimespan(savedSpan);
			}
		}
	}
}